//
//  XGAnswerQuestionViewModel.swift
//  TodayNews
//
//  Created by monkey on 2020/3/8.
//  Copyright © 2020 itcast. All rights reserved.
//

import UIKit

class XGAnswerQuestionViewModel
{
    /// 问题
    var question: String? {
        return answerQuestionModel.question?.title
    }
    /// 答案
    var answer: String? {
        return answerQuestionModel.answer?.text
    }
    /// 描述字符串
    private(set) var infoString: String
    /// 行高
    private(set) var rowHeight: CGFloat = 0
    
    init(answerQuestionModel: XGAnswerQuestionModel)
    {
        infoString = (answerQuestionModel.answer?.digg_count.countString ?? "0") + "赞"
        infoString += "    " + (answerQuestionModel.answer?.brow_count.countString ?? "0") + "阅读"
        infoString += "    " + (answerQuestionModel.answer?.show_time ?? "")
        
        rowHeight += 5
        let maxWidth = TodayNews_Screen_Width - 20
        if let question = answerQuestionModel.question?.title {
            rowHeight += 5 + XGCalculator.calculateString(text: question, width: maxWidth, fontSize: 17)
        }
        if let answer = answerQuestionModel.answer?.text {
            rowHeight += 5 + XGCalculator.calculateString(text: answer, width: maxWidth, fontSize: 15, maxHeight: 66.0)
        }
        rowHeight += 5 + 21
        rowHeight = ceil(rowHeight)
        
        self.answerQuestionModel = answerQuestionModel
    }
    
    private let answerQuestionModel: XGAnswerQuestionModel
}
